package com.apes.fn.business.fixedLoss.modle;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @program: apes-server
 * @description:
 * @author: czs
 * @create: 2022-09-29 11:38
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = LossReceivedApportion.CONST_TABLE_NAME,indexes = {
        @Index(name = "IDX_LOSSQUOTATION_ID", columnList = "lossQuotation_id")
})
public class LossReceivedApportion extends BaseModel {
    public static final String CONST_TABLE_NAME = "ser_received_apportion";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "定损回款分摊编码", padding = 4 , prefix = "FT")
    @Comment("ID")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "loss_received_item", referencedColumnName = "id")
    @Comment("回款明细")
    private LossReceivedItem lossReceivedItem;

    @Column(name = "apportion_order", length = 64)
    @Comment("分摊单号")
    private String apportionOrder;

    @Column(name = "apportion_order_type", length = 64)
    @Comment("分摊单据类型")
    private String apportionOrderType;

    @Column(name = "unappropriated_amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("未分摊金额")
    private double unappropriatedAmount = 0;

    @Column(name = "private_account_amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("私户未分摊金额")
    private double privateAccountAmount = 0;

    @Column(name = "apportion_amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("已分摊金额")
    private double apportionAmount = 0;

    @Column(name = "need_apportion_amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("需分摊金额")
    private double needApportionAmount = 0;

    @Column(name = "adjustment_amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("调整金额")
    private double adjustmentAmount = 0;

    @Column(name = "payment_amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("已缴款金额")
    private double paymentAmount = 0;

    private void setPaymentAmount(double paymentAmount) {
        this.paymentAmount = paymentAmount;
    }

    public void addPaymentAmount(double paymentAmount) {
        this.paymentAmount += paymentAmount;
    }

    @Column(name = "lossQuotation_id", length = 256)
    @Comment("定损单号")
    private String lossQuotationId;

    @Column(name = "type", length = 64)
    @Comment("类型")
    private String type = "RO";//RO-零售,DT-调整 RT-回款DT记录

    @Column(name = "finish",columnDefinition = "number(1,0) default 0")
    @Comment("完成")
    private boolean finish;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "received_date")
    @Comment("零售单到账时间")
    private Date receivedDate;


    @Column(name = "remark", length = 256)
    @Comment("备注")
    private String remark;

}
